$(function () {
    var chart_datagrid = $("#chart_datagrid");
    var chart_groupType = $("#groupType");
    var pie_dialog = $("#pie_dialog");
    var bar_dialog = $("#bar_dialog");

    $("#groupType").combobox("setValue","off.name");
    //$("#keyword").combobox("getValue").val();
    // 使用一个 methodObj 对象来统一管理方法
    var methodObj = {
        reload: function reload () {
            chart_datagrid.datagrid('reload');
        },

        query: function query() {
            var keyword = $("[name=keyword]").val();
            var groupType = $("[name=groupType]").val();
            var beginDate = $("[name=beginDate]").val();
            var endDate = $("[name=endDate]").val();


            chart_datagrid.datagrid('load', {
                keyword: keyword,
                groupType: groupType,
                beginDate: beginDate,
                endDate: endDate
            });
        },

        // 饼图
        openPie: function() {
            //alert(1);
            var args = $("input").serialize();
            console.log(args);
            /*
            pie_dialog.panel('open').panel('refresh',"/chart/formalClientByPie"+'?' + args);
            pie_dialog.dialog("vcenter");*/
            pie_dialog.dialog('center',{
                title: '正式学员报表',
                width: 600,
                height: 550,
                closed: true,
                cache: false,
                href: "/chart/formalClientByPie"+'?' + args,
                modal: false,

                // onLoad: init_merge_dialog()
            });
            pie_dialog.dialog("open")

        },

        // 柱状图
        openBar: function() {
            var args = $("input").serialize();
            console.log(args);
            // pie_dialog.dialog('open').panel('refresh',"/chart/formalClientByBar"+'?' + args);
            // pie_dialog.dialog("vcenter");

            bar_dialog.dialog('center',{
                title: '正式学员报表',
                width: 600,
                height: 550,
                closed: true,
                cache: false,
                href: "/chart/formalClientByBar"+'?' + args,
                modal: false,

                // onLoad: init_merge_dialog()
            });
            bar_dialog.dialog("open")

        }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    };

    // 有 data-cmd 属性的链接都需要统一绑定点击事件
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });

    //饼状统计
    pie_dialog.dialog({
        cache: false,
        title: "统计报表",
        width: 600,
        height: 520,
        modal: true,
        //border: 'thin',
        draggable: false,
        shadow: true,
        closed: true,
        href: "/chart/clientByPie",
        onOpen: function () {
            pie_dialog.dialog("center");
        }
    });


    //柱状统计
    bar_dialog.dialog({
        cache: false,
        title: "统计报表",
        width: 600,
        height: 520,
        modal: true,
        //border: 'thin',
        draggable: false,
        shadow: true,
        closed: true,
        href: "/chart/clientByBar",
        onOpen: function () {
            pie_dialog.dialog("center");
        }
    });

    chart_datagrid.datagrid({
        width: 800,
        fitColumns: true,
        striped: true,
        url: "/chart/queryClient",
        fit: true,
        columns: [[
            {field: 'groupType', title: "分组信息", width: 1},
            {field: 'totalFee', title: '已付总款', width: 1},
            {field: 'totalPay', title: '未付总款', width: 1},
        ]],
        toolbar: "#toolbar",
        rownumbers: true,
        singleSelect: true
    });
});




